<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:insert="~{include :: header('新增直播')}" />
    <th:block th:insert="~{include :: datetimepicker-css}" />
</head>
<body class="hold-transition">
<div class="container-fluid mt-2 mb-2">
    <form class="form-horizontal m" id="form-liveroom-add">
        <div class="form-group row">
            <label class="col-sm-3 col-form-label text-sm-right is-required">房间标题</label>
            <div class="col-sm-8">
                <input name="roomTitle" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-3 col-form-label text-sm-right is-required">房间最大人数</label>
            <div class="col-sm-8">
                <input name="maxUsers" class="form-control" type="text" required>
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-3 col-form-label text-sm-right">开始时间</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <input name="startTime" autocomplete="off"  class="form-control" placeholder="yyyy-MM-dd" type="text" >
                </div>
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-3 col-form-label text-sm-right">结束时间</label>
            <div class="col-sm-8">
                <div class="input-group date">
                    <input name="endTime" autocomplete="off"  class="form-control" placeholder="yyyy-MM-dd" type="text" >
                </div>
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-3 col-form-label text-sm-right">类型</label>
            <div class="col-sm-8">
                <select name="type" class="form-control m-b">
                    <option value="2" selected="selected">班课</option>
                    <option value="1">一对一课</option>
                </select>
            </div>
        </div>
        <div class="row">
            <label class="col-sm-3"></label>
                <div class="col-sm-8">
                <button type="button" class="btn btn-primary" onclick="addSubmit()"><i class="fa fa-check"></i>保 存</button>&nbsp;
                <button type="button" class="btn btn-danger" onclick="closeIndesx()"><i class="fa fa-reply-all"></i>关 闭 </button>
            </div>
        </div>
    </form>
</div>
<th:block th:insert="~{include :: footer}" />
<th:block th:insert="~{include :: datetimepicker-js}" />
<script type="text/javascript">
    var prefix = "/subject";

    $("input[name='startTime']").datetimepicker({
        format:'Y-m-d H:i:00',
        formatDate:'Y-m-d',
        formatTime:'H:i:00',
        step: 5
    });

    $("input[name='endTime']").datetimepicker({
        format:'Y-m-d H:i:00',
        formatDate:'Y-m-d',
        formatTime:'H:i:00',
        step: 5
    });

    //关闭窗口
    function closeIndesx() {
        window.parent.layer.closeAll();
    }

    /*添加直播间*/
    function addSubmit() {
        $.ajax({
            type:"POST",
            dataType:"json",
            url:"/course/node/live/add.json",
            data:$("#form-liveroom-add").serialize(),
            async:false,
            success:function(result){
                if (result.code === 0){
                    window.parent.$("#liveBeginTime").val($("input[name='startTime']").val());
                    window.parent.$("#liveEndTime").val($("input[name='endTime']").val());
                    window.parent.$("#liveUrl").val(result.msg);
                    $.modal.msgSuccess("创建成功！");
                    setTimeout(function () {
                        window.parent.layer.closeAll();
                    }, 1300);
                }else {
                    layer.msg(result.msg, {icon: 5, shift: 6});
                }
            }
        })
    }

    $("#form-subject-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-liveroom-add').serialize());
        }
    }


</script>
</body>
</html>